#include<stdio.h>
#include<omp.h>

// for 循环
static long num_steps = 1000000000;
double step;
double step;
double start, end;
#define NUM_THREADS 1

void main()
{	
    double pi=0.0, sum = 0.0;
	step = 1.0/(double)num_steps;
    omp_set_num_threads(NUM_THREADS);
    start = omp_get_wtime();
    #pragma omp parallel
    {
        double x;
        
        #pragma omp for reduction(+:sum)
        for(int i = 1; i < num_steps; i++){
            x = (i-0.5)*step;
            sum += 4.0/(1.0+x*x);
	    }    
        pi = sum * step;
    }
    end = omp_get_wtime();
    printf("pi = %.8f\n", pi);
     printf("time:%f", end - start);
}
